const DownInZoneData = require("./Savage_Main_Squad_DownInZone.json");
const ItemPickUp = require("./SavageMap_ItemPickup_InZones0713S.json");
const SafetyZoneData = require("./SavageMap_SafetyZone_20000.json");
const CityzonesGrids = require("./zonesGridsInSavageMap");
const fs = require("fs-extra");
const path  =require("path");

/**
 * @type  
 */
let last_results = {};

let nameToLower = (name) => {
  let _name = name.toLowerCase();
  while (_name.includes(" ")) {
    _name = _name.replace(" ", "")
  }
  return _name;
}

for (let zone of CityzonesGrids) {
  let name = zone['name']
  last_results[nameToLower(name)] = {
    name: zone['name'],
    down: 0,
    safezone: 0,
    items: 0,
    items_attachment: 0,
    items_use: 0,
    items_weapon: 0,
    grids_count: zone['grids_count']
  }
}
// debugger

for (let name in ItemPickUp) {
  let _name = nameToLower(name);
  last_results[_name]['items'] = ItemPickUp[name].items;
  last_results[_name]['items_attachment'] = ItemPickUp[name].Attachment;
  last_results[_name]['items_use'] = ItemPickUp[name].Use;
  last_results[_name]['items_weapon'] = ItemPickUp[name].Weapon;
}


for (let o of CityzonesGrids) {
  let valueSum = 0;
  for (let xi = o.zone_range[0][0]; xi <= o.zone_range[1][0]; xi++) {
    for (let yi = o.zone_range[0][1]; yi <= o.zone_range[1][1]; yi++) {
      valueSum += SafetyZoneData.GRIDS_IN_SMALL[xi][yi]
    }
  }
  // debugger
  let ave = valueSum / o.grids_count;
  console.log(nameToLower(o.name), "|", valueSum, "|", ave);
  last_results[nameToLower(o.name)]['safezone'] = ave
  // debugger
}
// debugger
for (let zn in DownInZoneData) {
  // debugger
  let length = DownInZoneData[zn].length;
  let grids_count = last_results[zn].grids_count;
  let ave = length / grids_count;
  last_results[zn]['down'] = ave;
  // debugger
}
debugger
fs.writeFile(path.join(__dirname,"./radar-0712.json"),JSON.stringify(last_results),()=>{
  debugger
})
// debugger


